<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link href="${ctx}/resources/semanticui/semantic.min.css"
	rel="stylesheet" type="text/css" />
<link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
<title>Hunter 邮箱验证</title>
</head>
<body>
	<div class="ui segment" id="n-page">

		<div class="ui segment" id="n-content">
			<form class="ui form">
				<div class="field">
					<label>邮箱</label>
					<div class="ui input">
						<input type="text" name="email" id="email" placeholder="请输入您的邮箱"
							value="">
					</div>
				</div>
				<div class="field">
					<label>验证码</label>
					<div class="ui input">
						<input type="text" name="code" id="code" placeholder="请输入验证码"
							value=""> &nbsp;
						<div class="ui button active dog" id="sendEmail">发送</div>
					</div>
				</div>

			</form>
		</div>
		
		<div class="ui checked checkbox">
		   <input type="checkbox" id="agreement" class="hidden" checked="">
			 
			<label>同意会猎公众号
				<a href="https://headoffer.com/hunterAgreement.htm">《用户使用协议》 </a>
			</label>
		</div>

		<div class="ui center aligned segment" id="choice-buttons">
			<div class="two ui buttons">
				<div class="ui button active dog" id="next">下一步</div>
				<div class="ui button active dog" id="closeit">回首页</div>
			</div>
		</div>
		<div class="ui center aligned segment">
			真实的注册<br> 严格的审核<br> 绝对的保密<br>
		</div>

	</div>

	<script src="${ctx}/resources/jweixin-1.0.0.js"></script>

	<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
	<script src="${ctx}/resources/semanticui/semantic.js"
		type="text/javascript"></script>
	<script type="text/javascript">

wx.config({
    debug: false, 
    appId: "${config.appid}",  
    timestamp: ${config.currenttimestamp},  
    nonceStr: "${config.nonceStr}", 
    signature: "${config.signatureStr}", 
    jsApiList: ['checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'hideOptionMenu',
        'closeWindow']  
});

 

    var handler = { 
        activate: function() { 
            $(this).addClass('active').siblings().removeClass('active'); 

            if($(this).attr('id') == 'closeit') {
                wx.closeWindow();
            }
            if($(this).attr('id') == 'sendEmail') {   
            	var postUrl = '${ctx}/wechat/headhunter/hunter/sendSecurityCode.do';
                var param = {};
                var email = $("#email").val();
                param['email']  = email;
                if(!email) {
                  alert("您必须输入电子邮箱");
                  return false;
              }
                $(this).addClass('disabled');
                var that = this;
                $.ajax({ 
                    url: postUrl, 
                    type: "GET", 
                    data: param,
                    success: function(data) { 
                      alert(data.msg);
                      
                    }, error: function(){ 
                            alert("服务出错，请稍后尝试"); 
                            $(that).removeClass('disabled');
                    } 
                    });
            }

            if($(this).attr('id') == 'next') {
               
                var email = $("#email").val();
                var code = $("#code").val();
                var hrid  = $("#hrid").val();
                if(!code || code=="") {
                    alert("您必须输入验证码");
                    return false;
                }
                if(!email) {
                    alert("您必须输入电子邮箱");
                    return false;
                }
                var re = /[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}/igm;
                if(!re.test(email)) {
                    alert("您必须输入合格的电子邮箱");
                    return false;
                }
               // if(!phone || phone =="") {
                  //alert("您必须输入手机号码");
                //  return false;
             // }
              //var regEx = /^1[0-9]{2}[0-9]{8}$/;
              //if (!phone.match(regEx)) {
              //    alert("您必须输入合格的手机号码");
              //    return false;
             // }
                $(this).addClass('disabled');
                var that = this;

                var postUrl = '${ctx}/wechat/hunter/bindeEmail.do';
                var param = {};
                param['secureCode']  = code;
                param['email']  = email;
                if (hrid) { 
                    param['id'] = hrid;
                }

                $.ajax({ 
                    url: postUrl, 
                    type: "POST", 
                    data: param,
                    success: function(data) { 
                        if(data.errorcode=="0"){
                            var hunter = data.data;
                            location.href = '${ctx}/wechat/hunter/toEdit.page?hunterId='+hunter.id;
                            return;
                        }  else if(data.errorcode=="1") {
                            alert(data.msg);
                          //  location.href = '${ctx}/wechat/employer/main.page';
                            return;
                        } else {
                            alert(data.msg);
                            $(that).removeClass('disabled');
                        }
                    }, 
                    error: function(){ 
                        alert("服务出错，请稍后尝试"); 
                        $(that).removeClass('disabled');
                    } 
                });
            }
        } 
    };
  

    $(document).ready(function() { 
       // wx.ready(function() {
            $('.button').on('click', handler.activate);
            // bind events to buttons
            $(' .checkbox') .checkbox() .first().checkbox({
        onChecked: function() {
          $('#next') .removeClass('disabled');
        },
        onUnchecked: function() {
          $('#next') .addClass('disabled');
        }
      })   ;      
            wx.hideOptionMenu();
       // });
    });

</script>
</body>
</html>